﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itfort.Web;
using WanPiJie.Products;

namespace WanPiJie.WebSite.MyBaby
{
	public partial class Index : PageMustLogin_Baby
	{
		/// <summary>
		/// 当前页码
		/// </summary>
		public int pageIndex
		{
			get
			{
				return 1;
			}
		}

		/// <summary>
		///当前尺寸 
		/// </summary>
		public int pageSize
		{
			get
			{
				return 12;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public int CatalogId { get; set; }

		/// <summary>
		/// 最新的一条成长记录
		/// </summary>
		protected GrowthRecord LastGrowthRecord { get; private set; }

		/// <summary>
		/// 与宝宝当前阶段匹配的成长发育指标
		/// </summary>
		protected GrowthIndicator GrowthIndicator { get; private set; }

		/// <summary>
		/// 最后一次成长记录距离当前天数
		/// </summary>
		protected int LastGrowthRecordFromDays
		{
			get
			{
				return (int)(DateTime.Today - this.LastGrowthRecord.SurveyDate).TotalDays;
			}
		}

        protected IList<Commodity> SalesInfoExtensions { get; private set; }

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			if (!this.HasBaby)
			{
				Response.Redirect("NoBaby.aspx");
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{

		}

		/// <summary>
		/// Http	Get请求处理
		/// </summary>
		protected override void HttpGetProcess()
		{
			base.HttpGetProcess();
			CatalogId = this.Request.ToInt32("cid");
			this.GrowthIndicator = WpjSf.GrowthIndicatorService.GetGrowthIndicatorByAge(this.Baby.GetAgeMonths());
			this.LastGrowthRecord = WpjSf.GrowthRecordService.GetLastGrowthRecord(this.Baby.Id);
			if (CatalogId == 0)
			{
				this.SalesInfoExtensions = WpjSf.CommodityService.GetCommodities((float)this.LastGrowthRecord.Weight, this.Baby.GetAgeDays(), this.Baby.Gender, this.pageIndex, this.pageSize);
			}
			else
			{
				this.SalesInfoExtensions = WpjSf.CommodityService.GetCommodities(CatalogId, (float)this.LastGrowthRecord.Weight, this.Baby.GetAgeDays(), this.Baby.Gender, this.pageIndex, this.pageSize);
			}

			this.rptProductList.DataSource = this.SalesInfoExtensions;
			this.DataBind();
		}
	}
}